package controllers.webapi


import play.api.Logging

import play.api.mvc.{AbstractController, BodyParsers, Codec, ControllerComponents}
import services.dingtalk.RobotMessageService

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

/**
 * This controller creates an `Action` to handle HTTP requests to the
 * application's home page.
 */
@Singleton
class RobotWebApi @Inject()(cc: ControllerComponents, robot: RobotMessageService)(implicit exec: ExecutionContext, parser: BodyParsers.Default)
  extends AbstractController(cc) with play.api.i18n.I18nSupport with Logging {
  implicit val myCustomCharset = Codec.javaSupported("gb18030")

  def index() = Action { implicit request =>
    Ok(views.html.index("Your new application is ready.中"))
  }

  def robotRouter(api: String) = Action { implicit request =>
    logger.debug(request.body.asText.getOrElse(""))
    request.map(r => logger.debug(r.asText.getOrElse("")))
    logger.debug(request.queryString.toString())
    Ok(api)
  }

}
